<template>
  <div>
    <el-row :gutter="15">
      <el-form
        ref="elForm"
        :model="formData"
        :rules="rules"
        size="medium"
        label-width="100px"
      >
        <el-col :span="24">
          <el-form-item label="用户账号" prop="userName">
            <el-input
              v-model="formData.userName"
              placeholder="请输入用户账号"
              :maxlength="30"
              clearable
              :style="{ width: '100%' }"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="密码" prop="password">
            <el-input
              v-model="formData.password"
              placeholder="请输入密码"
              clearable
              show-password
              :style="{ width: '100%' }"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="验证码" prop="vcode">
            <el-input
              v-model="formData.vcode"
              placeholder="请输入验证码"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <div @click="getVcode">
            <identifycode :identify-code="identifyCode_v"></identifycode>
          </div>
        </el-col>

        <el-col :span="24">
         <el-form-item label="地区" prop="area">
          <el-cascader
            v-model="formData.area"
            :options="options"
            :props="{ value: 'id', label: 'areaName', children: 'children' }"
            @change="handleChange"
          ></el-cascader>
         </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import identifycode from "vue-identifycode";

export default {
  components: {
    identifycode,
  },
  props: [],
  data() {
    return {
      identifyCode_v: "",

      formData: {
        userName: '',
        password: '',
        vcode: '',
        area: '',
      },
      rules: {
        userName: [
          {
            required: true,
            message: "请输入用户账号",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
        vcode: [
          {
            required: true,
            message: "请输入验证码",
            trigger: "blur",
          },
        ],
      },

      options: [],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.getTree();
    this.getVcode(); //生成随机验证码
  },
  methods: {
    getTree() {
      this.axios({
        url: "/api/Account/GetAreaList",
        method: "get",
      }).then((res) => {
        console.log(res.data);
        this.options = res.data.data; //获取层级树形数据
      });
    },
    getVcode(){
        var arr=[2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','A','H','I','J','K'];
        var strCode='';
        for (let index = 0; index < 5; index++) {
          var i = Math.floor(Math.random()*arr.length);
          strCode += arr[i];          
        }
        this.identifyCode_v = strCode;
        console.log('获取验证码',strCode);
    },
    handleChange(value) {
      console.log(value);
    },

    submitForm() {
      this.$refs["elForm"].validate((valid) => {
        if (!valid) return;
        // TODO 提交表单
        this.$session.set("user", "wangxuefeng");
        this.$cookies.set("uid", 123);
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
  },
};
</script>
<style>
</style>
